package com.study.springbootsecurity.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 系统用户实体类
 * @TableName sys_user
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_user")
@Schema(description = "系统用户实体")
public class SysUser implements Serializable {

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    @Schema(description = "用户ID", example = "1", accessMode = Schema.AccessMode.READ_ONLY)
    private Long id;

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    @Size(max = 16, message = "用户名长度不能超过16个字符")
    @TableField("username")
    @Schema(description = "用户名", required = true, example = "admin")
    private String username;

    /**
     * 密码
     */
    @TableField("pass")
    @Schema(description = "用户密码", required = true, example = "encrypted_password", accessMode = Schema.AccessMode.WRITE_ONLY)
    private String password;

    /**
     * 租户id
     */
    @TableField("tenant_id")
    @Schema(description = "租户ID", example = "1001", defaultValue = "0")
    private Integer tenantId;

    /**
     * 用户所属部门id
     */
    @TableField("dept_id")
    @Schema(description = "部门ID", example = "2001")
    private Integer deptId;

    /**
     * 电话
     */
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    @TableField("phone")
    @Schema(description = "手机号", example = "13800138000")
    private String phone;

    @TableField(value = "account_non_expired")
    @Schema(description = "账号是否未过期；0-已过期；1-未过期")
    private Boolean accountNonExpired;

    @TableField(value = "account_non_locked")
    @Schema(description = "账号是否未锁定；0-已锁定；1-未锁定")
    private Boolean accountNonLocked;

    @TableField(value = "credentials_non_expired")
    @Schema(description = "凭证是否未过期；0-已过期；1-未过期")
    private Boolean credentialsNonExpired;

    @TableField(value = "enabled")
    @Schema(description = "凭证是否启用；0-禁用；1-启用1")
    private Boolean enabled;

    /**
     * 删除标识;0-未删除；1-已删除
     */
    @TableLogic(delval = "1", value = "0")
    @TableField("is_delete")
    @Schema(description = "删除标识（0-未删除，1-已删除）", example = "0", defaultValue = "0", accessMode = Schema.AccessMode.READ_ONLY)
    private Integer isDelete;

    @TableField(exist = false)
    @Schema(description = "该用户所拥有角色,不对sysUser表进行映射")
    private List<Role> roles;


    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @Schema(description = "创建时间", example = "2023-01-01T12:00:00", accessMode = Schema.AccessMode.READ_ONLY)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间", example = "2023-01-01T12:00:00", accessMode = Schema.AccessMode.READ_ONLY)
    private LocalDateTime updateTime;

}
